const Koa = require("koa");
const app = new Koa();

const logger = require("./middleware/logger");

app.use(logger);

app.use(async (ctx, next) => {
    ctx.body = "1";
    await next();
    ctx.body += "5";
});

app.use(async (ctx, next) => {
    ctx.body += "2";
    await next();
    ctx.body += "4";
});

app.use(async (ctx) => {
    ctx.body += "3";
    await new Promise((resolve) => {
        setTimeout(() => {
            resolve();
        }, Math.random() * 5000);
    });
});

app.listen(3002, () => {
    console.log("Koa 服务器已启动");
});
